<?php
include("../include/config.inc.php");
include("userlogincheck.php");

$store_id=GetValueByKey(tableprefix."store","member_id",$userid,"store_id");
$sql_store="select account from ".tableprefix."store where store_state=1 and store_id='$store_id'";
$result_store=$db->query($sql_store);
$rs_store=$db->fetch_array($result_store);
$account=$rs_store["account"];
$db->free_result($result_store);

$todo=$_REQUEST["todo"];

if(isset($todo) && $todo=="todo")
{
	$cashamount=$_POST["cashamount"];
	$bank=$_POST["bank"];
	$nickname=$_POST["nickname"];
	$cardno=$_POST["cardno"];
	$createtime=date("Y-m-d H:i:s");
	$ip=getIP();
	$flag='T';
	$status="0";
	$accountnew=$account-$cashamount;
	$nowdate=date("Y-m-d");
	$cashtype='提现';

	if($cashamount==''){
		echo("<script type='text/javascript'>alert('请填写要提现的金额。');history.back(-1);</script>");
		exit;
	}
	if($cashamount<=99){
		echo("<script type='text/javascript'>alert('最少提现金额为100元。');history.back(-1);</script>");
		exit;
	}
	if($cashamount>$account){
		echo("<script type='text/javascript'>alert('提现金额不能大于可用余额。');history.back(-1);</script>");
		exit;
	}
	if($bank==''){
		echo("<script type='text/javascript'>alert('请选择开户银行。');history.back(-1);</script>");
		exit;
	}
	if($nickname==''){
		echo("<script type='text/javascript'>alert('请填写开户名称。');history.back(-1);</script>");
		exit;
	}
	if($cardno==''){
		echo("<script type='text/javascript'>alert('请填写银行卡号。');history.back(-1);</script>");
		exit;
	}
	$sql_cashout = "select count(*) as count from ".tableprefix."cashout where 1=1 and userid=$userid and cashtype='提现' and createtime like '%$nowdate%'";
	$rs_cashout=$db->fetch_array($db->query($sql_cashout));
	$count=$rs_cashout["count"];
	if($count>0){
		echo("<script type='text/javascript'>alert('您今天已经提现过了，一天只可以提现一次哦。');location.href='cashout.php';</script>");
		exit;
	}
		
	$sql="insert into ".tableprefix."cashout(amount,cashtype,bank,nickname,cardno,createtime,ip,storeid,userid,status,flag)values('$cashamount','$cashtype','$bank','$nickname','$cardno','$createtime','$ip','$store_id','$userid','$status','$flag')";
	$db->query($sql);
	$sql2="update ".tableprefix."store set account='$accountnew' where store_id=$store_id";
	$db->query($sql2);
	if(!$db->error())
	{
		$projectid=$db->insert_id();
		PhpBox('提现提交成功，请等待工作人员处理。');
		GotoPage('mywallet.php');
		$db->close();
		exit;
	}
	else
	{
		PhpBox('数据库出错！');
		GotoPage('../index.php');
		$db->close();
		exit;
	}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>余额提现 - 订戏会</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=9,Chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="keywords" content="">
<meta name="description" content="">
<link rel="stylesheet" type="text/css" href="../css/public.css">
<link rel="stylesheet" type="text/css" href="../css/user.css">
</head>

<body>
<form action="" method="post" name="myform" id="publishForm">
<input name="todo" type="hidden" value="todo">
<div class="wallet-info">
	<span><?php echo number_format($account,2);?></span>
	<p>可用余额（元）</p>
</div>

<div class="mod-form">
	<div class="form-group" style="margin-top:0px;">
		<div class="form-item">
			<label>提现金额</label>
			<input type="text" pattern="[0-9]*" maxlength="10" id="cashamount" name="cashamount" placeholder="请填写要提现的金额" value="">
			<span>元</span>
		</div>
	</div>
</div>

<div class="tips"><p>在订戏会平台申请提现的用户，在提现时会减去提现金金额的<font style="color:#FF0000;font-weight:500;">1%</font>,该费用为第三方支付通道收费及服务费。</p></div>

<div class="tips"><h1>提现到银行卡</h1></div>

<div class="mod-form">
	<div class="form-group" style="margin-top:0px;">
		<div class="form-item">
			<label>开户银行</label>
			<select name="bank" id="bank">
				<option value="">请选择开户银行</option>
				<option value="中国工商银行">中国工商银行</option>
				<option value="中国建设银行">中国建设银行</option>
				<option value="中国农业银行">中国农业银行</option>
				<option value="中国银行">中国银行</option>
				<option value="交通银行">交通银行</option>
				<option value="中国民生银行">中国民生银行</option>
				<option value="中国光大银行">中国光大银行</option>
				<option value="中国邮政储蓄银行">中国邮政储蓄银行</option>
				<option value="招商银行">招商银行</option>
				<option value="广发银行">广发银行</option>
				<option value="中信银行">中信银行</option>
				<option value="兴业银行">兴业银行</option>
				<option value="浦发银行">浦发银行</option>
				<option value="平安银行">平安银行</option>
	        </select>
		</div>
		<div class="form-item">
			<label>开户名称</label>
			<input type="text" maxlength="50" id="nickname" name="nickname" placeholder="请填写开户名称(个人或单位)" value="">
		</div>		
		<div class="form-item">
			<label>银行卡号</label>
			<input type="text" maxlength="20" id="cardno" name="cardno" placeholder="请填写银行卡号" value="">
		</div>
	</div>
</div>

<div class="form-button"><input name="s" type="submit" id="s" value="确定提现" /></div>
<div class="back"><a href="mywallet.php"><div class="backup">返回</div></a></div>
</form>
</body>
</html>